package newcoder_exp.justPractise;

import java.util.Arrays;
import org.junit.*;
//最优服务次序
public class Pra7 {
    
    //单服务
    public double singleServer(int[] times) {
        int n = times.length;
        Arrays.sort(times);
        int t = n, sum = 0;
        for (int i = 0; i < n; i++) {
            sum += times[i] * (t--);
        }
        return sum / (double)n;
    }

    //有k个人可以同时提供服务，求最短服务时间
    public double multiServer(int[] times, int k) {
        //just try
        int[] t = new int[k];
        int n = times.length;
        int[] sum = new int[k];//记录每组的最短服务时间
        Arrays.sort(times);
        int temp;
        int s = 0;
        for (int i = 0; i < n; i++) {
            temp = i % k;
            t[temp] += times[i];
            sum[temp] += t[temp];
            s += times[i];
        }
        int summry = 0;
        for (int i = 0; i < k; i++) {
            summry += sum[i];
        }
        System.out.println(Arrays.toString(times));
        System.out.println(Arrays.toString(t) + "    " + Arrays.toString(sum) + " "  + s);
        return summry / (double)n;
    }
    @Test
    public void test() {
        int[] times = new int[]{56,12,1,99,1000 ,234, 33 ,55, 99, 812};
        System.out.println(singleServer(times));
        System.out.println(multiServer(times, 2));
    }
}
